<!--
 * new page
 * @author: liuxin
 * @since: 2024-08-16
 * delete_admin.vue
-->
<template>
	<el-dialog v-model="dialogFormVisible" title='再次申请出库' width="30%" center>
		<span>请确认，此操作将再次申请产品出库</span>
		<template #footer>
			<span class="dialog-footer">
				<el-button type="primary" @click="applyProductFn">确定</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, onBeforeUnmount } from "vue"
import { bus } from "@/utils/mitt.js"
import { applyOutProduct } from '@/api/product.js'
import { ElMessage } from 'element-plus'

bus.on('againId', (row: any) => {
	formData.id = row.id
	formData.product_inwarehouse_number = row.product_inwarehouse_number
	formData.product_name = row.product_name
	formData.product_single_price = row.product_single_price
	formData.product_out_apply_person = row.product_out_apply_person
	formData.product_out_number = row.product_out_number
})
interface FormData {
	id: number | null,
	product_name: string,
	product_out_id: number | null,
	product_inwarehouse_number: number | null,
	product_single_price: number | null,
	product_out_number: number | null,
	product_out_apply_person: string,
	apply_memo: string
}

const formData: FormData = reactive({
	id: null,
	product_name: '',
	product_out_id: null,
	product_inwarehouse_number: null,
	product_single_price: null,
	product_out_number: null,
	product_out_apply_person: '',
	apply_memo: ''
})
const emit = defineEmits(['success'])
// 再次申请产品出库
const applyProductFn = async () => {
	const res = await applyOutProduct(formData)
	if (res.status == 0) {
		ElMessage({
			message: '申请出库成功',
			type: 'success'
		})
		emit('success')
		dialogFormVisible.value = false
	} else {
		ElMessage.error('申请出库失败')
		dialogFormVisible.value = false
	}
}


// 弹窗开关

const dialogFormVisible = ref(false)
// 打开编辑管理员弹窗
const open = () => {
	dialogFormVisible.value = true
}
defineExpose({
	open
})

// 取消订阅/监听
onBeforeUnmount(() => {
	bus.all.clear()
})
</script>

<style scoped lang="scss"></style>